package com.leyou.common.advice;

import com.leyou.common.exceptions.LyException;
import com.leyou.common.exceptions.result.LyExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class BaseExceptionAdvice {

    /**
     * 通用运行期异常处理
     */
    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity<String> handleRuntimeException(RuntimeException e){
        return ResponseEntity.status(500).body(e.getMessage());
    }

    /**
     * 通用乐优异常处理
     */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<LyExceptionResult> handleLyException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(new LyExceptionResult(e));
    }


}
